package javagames.util;

public class FrameRate {
	private String frameRate;
	private String frameDelta;
	private long lastTime;
	private long delta;
	private int frameCount;
	
	public void initialize(){
		lastTime = System.currentTimeMillis();
		frameRate = "FPS 0";
		frameDelta = "Delta 0";
	}
	
	public void calculate(){
		long current = System.currentTimeMillis();
		delta += current -lastTime;
		lastTime = current;
		frameCount++;
		
		if (delta > 1000){
			delta -=1000;
			frameRate = String.format("FPS %s", frameCount);
			frameDelta = String.format("Delta %s", delta);
			frameCount = 0;
		}
	}
	
	public String getFrameRate(){
		return frameRate;
	}
	
	public String getFrameDelta(){
		return frameDelta;
	}
}
